import { _decorator, Button, Component, Input, input, instantiate, KeyCode, Label, Layout, macro, math, Node, Prefab, size, Sprite, SpriteFrame, sys, UITransform, v3, Vec3 } from 'cc';
import { GameMgr } from '../manager/GameMgr';
import { ArrayUtil } from '../util/ArrayUtil';
import { ShelveType } from '../enum/ShelveType';
import { ShelveLocker } from './ShelveLocker';
import { ShelveBase } from '../scriptBase/ShelveBase';
import { CommonShelve } from './CommonShelve';
import { SmallShelve } from './SmallShelve';
import { UIMgr } from '../manager/UIMgr';
import { UI } from '../enum/UI';
import { PREVIEW } from 'cc/env';
import { Mode, ModeName, ModeType } from '../enum/Mode';
import { cfg_level_gs, cfg_level_ls, cfg_level_tp } from '../config/cfg_level';
import { DtoLevelCfg } from '../dto/DtoLevelCfg';
import { DtoLevelData } from '../dto/DtoLevelData';
import { cfg_icon_gs, cfg_icon_ls, cfg_icon_sk, cfg_icon_tp } from '../config/cfg_icon';
import { DtoIconCfg } from '../dto/DtoIconCfg';
import { ResMgr } from '../manager/ResMgr';
import { Bundle } from '../enum/Bundle';
import { Global } from '../Global';
import { EventMgr } from '../manager/EventMgr';
import { EventType } from '../enum/EventType';
import { CoinMgr } from '../manager/CoinMgr';
import { ComboBox } from './ComboBox';
import { Goods } from './Goods';
import { AudioMgr } from '../manager/AudioMgr';
import { Setting } from '../Setting';
import { SkillType } from '../enum/SkillType';
const { ccclass, property } = _decorator;

@ccclass('Game/Stage')
export class Stage extends Component {

    @property(Sprite)
    private bg: Sprite = null
    @property([SpriteFrame])
    private bgArr: SpriteFrame[] = []
    @property(Node)
    private shelveBox: Node = null
    @property(ComboBox)
    private comboBox: ComboBox = null
    @property(Node)
    private tip: Node = null
    @property(Prefab)
    private shelveLockerPre: Prefab = null
    @property(Prefab)
    private shelvePreArr: Prefab[] = []

    @property(Label)
    private lbLevel: Label = null;

    @property(Label)
    private lbTitle: Label = null;

    @property(Label)
    private lblDes: Label = null;

    @property(Label)
    private lalStep: Label = null;

    @property(Node)
    private dobNode: Node = null;

    @property(Node)
    private rightNode: Node = null;

    @property(Label)
    private lalRightNum: Label = null;

    @property(Node)
    private tip1: Node = null;

    @property(Node)
    private tip2: Node = null;

    @property(Node)
    private campNode: Node = null;

    private levelCfg: DtoLevelCfg = null
    private levelData: DtoLevelData = null
    private iconCfg: DtoIconCfg = null

    private shelveArr: ShelveBase[] = []

    private doubleCoin: boolean = false

    private isBusy: boolean = false

    private isReceive:number = 0;   //复活次数

    @property(Node)
    private initBoxNode: Node = null        //初始拖拽Node

    @property(Goods)
    private initGood: Goods = null

    @property(Node)
    private initBtn: Node = null

    @property(Label)
    private initStatuLab: Label = null

    @property(Label)
    private initStatuTimeLab: Label = null

    @property(Node)
    private notBtn: Node = null

    @property(Node)
    private skillNode: Node = null

    /** 0抽取中，1可验证，2回想中 */
    gameStatu:number = 0;

    huixiangTime:number = 15;


    protected onLoad(): void {
        // const bgName: string = 'bg_' + ModeName[GameMgr.mode]
        // this.bg.spriteFrame = ResMgr.getSpriteFrame(Bundle.Game, bgName, 'image/')
        this.bg.spriteFrame = this.bgArr[GameMgr.mode];
        this.isReceive = 0;

        EventMgr.on(EventType.MergeGoods, this.onMergeGoods, this)
        EventMgr.on(EventType.TimeOut, this.onTimeOut, this)
        EventMgr.on(EventType.TimeOutAlert, this.onTimeOutAlert, this)
        EventMgr.on(EventType.UseSkillFreezeTime, this.onUseSkillFreezeTime, this)
        EventMgr.on(EventType.UseSkillDoubleCoin, this.onUseDoubleCoin, this)
        EventMgr.on(EventType.UseSkillRefreshPosition, this.onUseRefreshPos, this)
        EventMgr.on(EventType.UseSkillEraseGroup, this.onUseEraseGroup, this)
        EventMgr.on(EventType.GameRefresh, this.onRefresh, this)
        EventMgr.on(EventType.RefreshInitBox, this.refreshInitBox, this)

        if (PREVIEW) {
            input.on(Input.EventType.KEY_DOWN, (e) => {
                if (e.keyCode !== KeyCode.KEY_Q) return
                if (GameMgr.Pause) return
                UIMgr.open(UI.Win, 1)
            }, this)
        }

        this.onRefresh();
    }



    protected onDestroy(): void {
        UIMgr.close(UI.Game)
        this.unscheduleAllCallbacks()

        EventMgr.off(EventType.MergeGoods, this.onMergeGoods, this)
        EventMgr.off(EventType.TimeOut, this.onTimeOut, this)
        EventMgr.off(EventType.TimeOutAlert, this.onTimeOutAlert, this)
        EventMgr.off(EventType.UseSkillFreezeTime, this.onUseSkillFreezeTime, this)
        EventMgr.off(EventType.UseSkillDoubleCoin, this.onUseDoubleCoin, this)
        EventMgr.off(EventType.UseSkillRefreshPosition, this.onUseRefreshPos, this)
        EventMgr.off(EventType.UseSkillEraseGroup, this.onUseEraseGroup, this)
        EventMgr.off(EventType.GameRefresh, this.onRefresh, this)
        EventMgr.off(EventType.RefreshInitBox, this.refreshInitBox, this)
    }

    protected start() {
        UIMgr.open(UI.Game)
        //this.tip.active = GameMgr.mode === Mode.tp && GameMgr.CurLevel === 0
        this.scheduleOnce(() => {
            //if (GameMgr.isHardLevel) UIMgr.open(UI.StageTip, '难度飙升')
        }, 1)

        GameMgr.gameCampSum = 1

        GameMgr.gameCampCur = 0;

        this.levelCfg = cfg_level_tp
        this.iconCfg = cfg_icon_tp

        if (GameMgr.modeType == ModeType.caipingWang){
            this.levelCfg = cfg_level_ls
        }else if (GameMgr.modeType == ModeType.caipingQinglv || GameMgr.modeType == ModeType.caipingDashi){
            this.levelCfg = cfg_level_gs
            this.levelData = this.levelCfg[GameMgr.selectLev] 

            GameMgr.gameCampSum = 2
        }

        if (!this.levelData){
            if (GameMgr.CurLevel >= this.levelCfg.length) {
            this.levelData = ArrayUtil.pickItem(this.levelCfg)
            if (GameMgr.modeType == ModeType.caipingWang){
                this.levelData = this.levelCfg[1]
            }
            } else {
                this.levelData = this.levelCfg[GameMgr.CurLevel] 
            }
        }
        // this.levelData = this.levelCfg[0] 
        this.levelData.lockCnt = 0;

        const shelveMap: number[][] = this.levelData.shelveMap
        const group: number = this.levelData.group
        const lockCnt: number = this.levelData.lockCnt
        const goodsTypeCnt: number = this.levelData.GoodsTypeCnt

        Global.Level_Time = this.levelData.time

        this.lbLevel.string = `第${GameMgr.CurLevel + 1}关`
        // Global.Level_Time = 10

        EventMgr.emit(EventType.TimeReset)

        this.createShelves(shelveMap)
        this.createShelveLockers(lockCnt)
        this.createGoodsArr(group, goodsTypeCnt)
        this.createGoodsData()

        let tileArr = ["猜瓶子", "猜瓶子闯关","猜瓶之王","猜瓶子（大师模式）","猜瓶子（情侣模式）",]
        this.lbTitle.string = tileArr[GameMgr.modeType];

        this.campNode.active = false;
        this.lbTitle.node.active = true;
        this.dobNode.active = false;
        // this.lblDes.node.active = true;
        this.lbLevel.node.active = true;
        if (GameMgr.modeType == ModeType.caipingChuangguan || GameMgr.modeType == ModeType.caipingWang ){
            this.initBoxNode.active = false;
            this.rightNode.active = true;
            this.rightNode.setPosition(0,-505,0);

            this.schedule(this.onCheckWin, 0.5, macro.REPEAT_FOREVER)
        }else{
            this.initBoxNode.active = true;
            this.rightNode.active = false;
            this.rightNode.setPosition(0,-270,0);

            this.notBtn.active = false;

            if (GameMgr.modeType == ModeType.caipingQinglv || GameMgr.modeType == ModeType.caipingDashi){
                this.lbTitle.string = tileArr[GameMgr.modeType] + " " + this.levelData.group + "瓶";
                this.lbLevel.node.active = false;
            }
        }

        if (GameMgr.modeType == ModeType.caipingWang){
            let now = new Date();
            this.lbTitle.node.active = false;
            this.lbLevel.string = `${now.getMonth() + 1}月${now.getDate()}日`;

            this.lblDes.string = GameMgr.CurLevel==0?"猜出瓶子的正确顺序":"今日通关率: 0.0014%";
        }

        this.onRefresh();
    }

    onRefresh(){
        // this.bg.node.active = !GameMgr.isBlackBg;
        // this.bg_black.node.active = GameMgr.isBlackBg;
        if (GameMgr.modeType == ModeType.caipingChuangguan){
            this.lalStep.string = "剩余步数" + GameMgr.stepNum + "/" +  this.levelData.step;
            if (GameMgr.stepNum >= this.levelData.step){
                UIMgr.open(UI.Win, 2)
            }
        }else{
             this.lalStep.string = "";

             if (this.gameStatu == 1){
                this.initStatuLab.string = "验证"
                this.notBtn.active = false;
                this.rightNode.active = false;

                this.initStatuTimeLab.string = "剩余" + (this.levelData.step - GameMgr.sureNum) + "次数";
             }
             else if (this.gameStatu == 2){
                this.initStatuLab.string = "回想中"
                this.notBtn.active = true;

             }
        }
       
        this.tip1.active = GameMgr.itemStatu==1;

        this.tip2.active = GameMgr.itemStatu==2;

        
        if (GameMgr.gameCampSum >= 2){
            this.campNode.active = true;
            this.dobNode.active = true;

            for (let index = 0; index < this.campNode.children.length; index++) {
                const element = this.campNode.children[index];
                element.active =  GameMgr.gameCampCur == index;
            }

            for (let index = 0; index < this.dobNode.children.length; index++) {
                const element = this.dobNode.children[index];
                element.getChildByName("winLab").getComponent(Label).string = GameMgr.gameCampWin[index] + "胜";
            }
        }
    }

    refreshInitBox(){
        if (GameMgr.goodsArrInit.length > 0){
            let goodId = GameMgr.goodsArrInit.shift();
            this.initGood.Id = goodId;
            this.initGood.Layer = 0;
            this.initGood.Slot = 0;
            this.initGood.comShelveId = -1;

            this.initGood.node.active = true;
            this.initGood.Visible = true

            this.initBtn.getComponent(Button).interactable = false;
            this.initStatuLab.string = "";
            this.initStatuTimeLab.string = "";

            this.gameStatu = 0
        }else{
            this.initBtn.getComponent(Button).interactable = true;
            this.initStatuLab.string = "";
            this.initStatuTimeLab.string = "";

            this.initGood.node.active = false;

            this.gameStatu = 1
        }
        
    }

    private createShelves(shelveMap: number[][]): void {
        const row: number = shelveMap.length
        const col: number = shelveMap[0].length
        let count:number = 0;
         for (let i = 0; i < shelveMap.length; i++) {
            for (let j = 0; j < shelveMap[i].length; j++) {
                const type: ShelveType = shelveMap[i][j]
                if (type == 1){
                    count++;
                }
            }
        }
        const uiTrans: UITransform = this.shelveBox.getComponent(UITransform)
        let lay:Layout = this.shelveBox.getComponent(Layout)
        const spaceX: number = 0
        const spaceY: number = 0
        uiTrans.width = count>= 7 ? 700: count*100 + spaceX * (col - 1) //col * 250 + spaceX * (col - 1)
        // uiTrans.height = 200 //row * 160 + spaceY * (row - 1)

        let scal:number = 1
        if (GameMgr.modeType == ModeType.caipingWang){
            if (GameMgr.CurLevel == 0){
                uiTrans.width = 450;
                uiTrans.height = 600;
                lay.spacingX = 200;
                lay.spacingY = 100;

                this.shelveBox.setPosition(0,20,1);
            }else{
                uiTrans.width = 700;
                uiTrans.height = 900;
                lay.spacingX = 0;
                lay.spacingY = -30;
                // lay.cellSize = new math.Size(70,200)
                scal = 0.7;

                this.shelveBox.setPosition(0,140,1);
            }
            this.skillNode.children[2].active = false;
        }else if (this.levelData.group > 7) {
            scal = 0.7;
            uiTrans.height = 700;
            uiTrans.width = 700
            lay.spacingY = 160;
            lay.spacingX = 20;

            this.shelveBox.setPosition(0,-50,1);
        }

        let curId:number = 1;
        for (let i = 0; i < shelveMap.length; i++) {
            for (let j = 0; j < shelveMap[i].length; j++) {
                const type: ShelveType = shelveMap[i][j]
                const shelvePre: Prefab = this.shelvePreArr[type]
                const shelveNode: Node = instantiate(shelvePre)
                let shelve:ShelveBase = shelveNode.getComponent(ShelveBase);
               
                shelveNode.setScale(scal,scal,1);
                this.shelveBox.addChild(shelveNode)
                // shelve.id = curId;
                // curId++;
            }
        }

        this.shelveArr = this.shelveBox.getComponentsInChildren(ShelveBase)
    }

    private createShelveLockers(lockCnt: number): void {
        if (lockCnt <= 0) return
        const shelves: ShelveBase[] = ArrayUtil.pickItems(this.shelveArr, lockCnt, true)
        for (let i = 0; i < shelves.length; i++) {
            const shelve: ShelveBase = shelves[i];
            const shelveLockerNode: Node = instantiate(this.shelveLockerPre)
            shelve.node.addChild(shelveLockerNode)
            const shelveLocker: ShelveLocker = shelveLockerNode.getComponent(ShelveLocker)
            shelveLocker.UnlockCnt = math.randomRangeInt(3, 6)
        }
    }

    private createGoodsArr(group: number, goodsTypeCnt: number): void {
        const idxArr: number[] = ArrayUtil.pickIndexs(this.iconCfg, goodsTypeCnt, false)
        GameMgr.goodsArr = []
        GameMgr.rightGoodId = []

        for (let i = 0; i < group; i++) {
            let goodsId:number = 0
            if (group < idxArr.length-1){
                goodsId = idxArr[i] + 1
            }else{
                goodsId = ArrayUtil.pickItem(idxArr) + 1
            }
            // GameMgr.goodsArr.push(goodsId, goodsId, goodsId)
            GameMgr.goodsArr.push(goodsId)
            GameMgr.rightGoodId.push(goodsId);
        }

        ArrayUtil.shuffle(GameMgr.rightGoodId)
        ArrayUtil.shuffle(GameMgr.goodsArr)

        while(JSON.stringify(GameMgr.rightGoodId) == JSON.stringify(GameMgr.goodsArr)){
            ArrayUtil.shuffle(GameMgr.rightGoodId)
        }
    }

    private createGoodsData(): void {

        const commonShelveArr: CommonShelve[] = []
        const smallShelveArr: SmallShelve[] = []

        for (let i = 0; i < this.shelveArr.length; i++) {
            const shelve: ShelveBase = this.shelveArr[i];
            if (shelve instanceof CommonShelve) {
                commonShelveArr.push(shelve)
            } else if (shelve instanceof SmallShelve) {
                smallShelveArr.push(shelve)
            }
        }

        //先悬浮格子
        // for (let i = 0; i < smallShelveArr.length; i++) {
        //     const smallShelve: SmallShelve = smallShelveArr[i];
        //     const smallShelveId: number = smallShelve.Id
        //     if (!GameMgr.goodsData.hasOwnProperty(smallShelveId)) {
        //         GameMgr.goodsData[smallShelveId] = {
        //             0: [],
        //         }
        //     }
        //     // const cnt: number = math.randomRangeInt(2, 4)
        //     for (let j = 0; j < 3; j++) {
        //         const goodsId: number = GameMgr.goodsArr.shift()
        //         GameMgr.goodsData[smallShelveId][0].push(goodsId)
        //     }
        // }

        const placeCnt: number = commonShelveArr.length // * 3

        
        if(GameMgr.modeType != ModeType.caipingChuangguan && GameMgr.modeType != ModeType.caipingWang){
            GameMgr.goodsArrInit = GameMgr.goodsArr.concat();
            GameMgr.goodsArr = [];

            this.refreshInitBox();
        }
        while (GameMgr.goodsArr.length > 0) {

        //筛选槽位
        const placeArr: number[] = []
        for (let i = 0; i < placeCnt; i++) {
            placeArr.push(i)
        }
        ArrayUtil.shuffle(placeArr)

        // if (placeCnt <= 6) {
        //     placeArr.splice(0, math.randomRangeInt(2, 3))
        // } else {
        //     placeArr.splice(0, math.randomRangeInt(4, 6))
        // }

        for (let i = 0; i < placeCnt; i++) {
            const placeId: number = i
            const commonShelveId: number = commonShelveArr[Math.floor(placeId)].Id
            const slotId: number = 0; //placeId % 3
            if (!GameMgr.goodsData.hasOwnProperty(commonShelveId)) {
                GameMgr.goodsData[commonShelveId] = {
                    0: [],
                    1: [],
                    2: [],
                }
            }
            let goodsId: number = -1
            if (GameMgr.goodsArr.length <= 0 || !placeArr.includes(placeId)){
                goodsId = -1
            } 
            else {
                goodsId = GameMgr.goodsArr.shift()
            }
            GameMgr.goodsData[commonShelveId][slotId].push(goodsId)
        } 
        }

        console.log("格子数组：",  GameMgr.goodsData)

    }

    private onCheckWin(): void {
        const isWin: boolean = this.checkWin()
        if (!isWin) return
        if (this.isBusy) return
        this.unscheduleAllCallbacks()

        UIMgr.open(UI.Win, 1)
    }

    private checkWin(): boolean {
        let count:number = 0;
        for (let i = 0; i < this.shelveArr.length; i++) {
            const shelve: ShelveBase = this.shelveArr[i];
            if (shelve.isEmpty){
                count++;
            }
        }
        this.lalRightNum.string = count + "";

        GameMgr.rightMaxNum = Math.max(GameMgr.rightMaxNum, count)

        for (let i = 0; i < this.shelveArr.length; i++) {
            const shelve: ShelveBase = this.shelveArr[i];
            if (!shelve.isEmpty) return false
        }
        return true
    }

    private onTimeOut(): void {
        if (this.isReceive > 0){
            const isWin: boolean = this.checkWin()
            if (isWin) return
            UIMgr.open(UI.Win, 2)
        }else{
            this.isReceive++;
            const isWin: boolean = this.checkWin()
            if (isWin) return
            UIMgr.open(UI.TimeOut)
        }
        
    }

    private onTimeOutAlert(): void {
        const effectRedAlertPre: Prefab = ResMgr.getRes(Bundle.Game, 'EffectRedAlert')
        const effectRedAlertNode: Node = instantiate(effectRedAlertPre)
        this.node.addChild(effectRedAlertNode)
    }

    private onUseSkillFreezeTime(): void {
        const effectFreezePre: Prefab = ResMgr.getRes(Bundle.Game, 'EffectFreeze')
        const effectFreezeNode: Node = instantiate(effectFreezePre)
        this.node.addChild(effectFreezeNode)
    }

    private onMergeGoods(shelveWorldPos: Vec3): void {
        // this.comboBox.CurCombo++
        // AudioMgr.playSfx(`bomb_${this.comboBox.CurCombo}`)
        // CoinMgr.CurCoin += this.doubleCoin ? this.comboBox.CurCombo * 2 : this.comboBox.CurCombo
        // this.comboBox.createFloatText(shelveWorldPos)

        if ( Setting.VibrateEnabled && sys.platform == sys.Platform.BYTEDANCE_MINI_GAME){
            // if (tt){
            //     tt.vibrateShort();
            // }
        }
    }

    private onUseDoubleCoin(): void {
        AudioMgr.playSfx('星星道具')
        this.doubleCoin = true
        this.scheduleOnce(this.onAfterDoubleCoin, Global.Double_Coin_Duration)
    }

    private onAfterDoubleCoin(): void {
        this.doubleCoin = false
    }

    private onUseRefreshPos(): void {
        AudioMgr.playSfx('转换道具')
        for (let i = 0; i < this.shelveArr.length; i++) {
            const shelve: ShelveBase = this.shelveArr[i]
            const goodsIdArr: number[] = shelve.GoodsIdArr
            for (let j = 0; j < goodsIdArr.length; j++) {
                const goodsId: number = goodsIdArr[j];
                GameMgr.goodsArr.push(goodsId)
            }
        }

        ArrayUtil.shuffle(GameMgr.goodsArr)

        this.createGoodsData()

        for (let i = 0; i < this.shelveArr.length; i++) {
            const shelve: ShelveBase = this.shelveArr[i]
            shelve.clear()
            this.scheduleOnce(() => {
                shelve.init()
            })
        }

        this.isBusy = true
        this.scheduleOnce(() => {
            this.isBusy = false
        }, 0.5)

    }

    private onUseEraseGroup(): void {

        AudioMgr.playSfx('灯泡道具')

        //先统计场上的物品
        const goodsMap = {}
        for (let i = 0; i < this.shelveArr.length; i++) {
            const shelve: ShelveBase = this.shelveArr[i];
            const info: Object = shelve.GoodsInfo
            for (const layer in info) {
                if (Object.prototype.hasOwnProperty.call(info, layer)) {
                    for (const slot in info[layer]) {
                        if (Object.prototype.hasOwnProperty.call(info[layer], slot)) {
                            const goods: Goods = info[layer][slot];
                            const goodsId: number = goods.Id
                            if (!goodsMap.hasOwnProperty(goodsId)) {
                                goodsMap[goodsId] = []
                            }
                            goodsMap[goodsId].push(goods)
                        }
                    }
                }
            }

            for (const goodsId in goodsMap) {
                if (Object.prototype.hasOwnProperty.call(goodsMap, goodsId)) {
                    ArrayUtil.shuffle(goodsMap[goodsId])
                }
            }

        }

        //筛选出超过三个的物品
        const map2 = {}

        for (const goodsId in goodsMap) {
            if (Object.prototype.hasOwnProperty.call(goodsMap, goodsId)) {
                if (goodsMap[goodsId].length >= 3) {
                    map2[goodsId] = goodsMap[goodsId]
                }
            }
        }

        //从中挑选三组
        const map3 = {}
        let cnt: number = 0
        for (const goodsId in map2) {
            if (Object.prototype.hasOwnProperty.call(map2, goodsId)) {
                map3[goodsId] = map2[goodsId]
                cnt++
                if (cnt >= 1) break
            }
        }

        //将这三组中随机三个物品消除
        for (const goodsId in map3) {
            if (Object.prototype.hasOwnProperty.call(map3, goodsId)) {
                const goodsArr: Goods[] = map3[goodsId];
                const pickedGoodsArr: Goods[] = ArrayUtil.pickItems(goodsArr, 3, true)
                for (let i = 0; i < pickedGoodsArr.length; i++) {
                    const goods: Goods = pickedGoodsArr[i];
                    const shelve: ShelveBase = goods.node.parent.parent.getComponent(ShelveBase)
                    if (!shelve) {
                        continue
                    }
                    shelve.removeGoods(goods)
                }
            }
        }

    }

    onItemClickHandler(eve:Event, str:string){
        if (GameMgr.itemStatu != 0){
            return;
        }
        if (str == "item1"){
            UIMgr.open(UI.GetSkill, SkillType.FreezeTime)
        }
        if (str == "item2"){
            GameMgr.itemStatu = 1
            this.onRefresh();
        }
        if (str == "item3"){
            GameMgr.itemStatu = 2
            this.onRefresh();
        }
        else if (str == "setting"){
            UIMgr.open(UI.Pause)
        }
        else if (str == "yanzheng"){
            if (this.gameStatu == 2){
                this.huixiangEnd();
                return;
            }
            GameMgr.sureNum++;
            const isWin: boolean = this.checkWin()
            if (isWin){
                this.onCheckWin();
            }else{
                this.gameStatu = 2
                if (GameMgr.sureNum >= this.levelData.step){
                    UIMgr.open(UI.Win, 2)
                }else{
                    this.rightNode.active = true;
                    this.notBtn.active = true;

                    this.initStatuLab.string = "回想中";

                    this.huixiangTime = 15;
                    this.initStatuTimeLab.string = this.huixiangTime+"秒";
                    this.schedule(this.updateTime, 1)
                    
                }
            }
        }
    }

    updateTime(){
        this.huixiangTime--;
        if (this.huixiangTime <= 0){
            this.huixiangEnd();
        }else{
            this.initStatuTimeLab.string = this.huixiangTime+"秒";
        }
    }

    //结束回想
    huixiangEnd(){
         if (GameMgr.gameCampSum >= 2){
             GameMgr.gameCampCur++;
            if ( GameMgr.gameCampCur >= GameMgr.gameCampSum){
                 GameMgr.gameCampCur = 0
            }
        }
        this.unschedule(this.updateTime);
        this.gameStatu = 1
        this.onRefresh();
       
    }

}



